/**
 * Created by yhg97p on 2016/9/27.
 */
define(['app', 'filters/filters'], function(app) {
	app.register.controller('compSet', function($scope, $http, $state, $sce, $stateParams, $rootScope, $confirm) {
        $scope.loading_show = true;
		$scope.load = {
			_getCompinfo: function() { //企业整体信息
				$http({
					url: app._baseUrl + '/QyManage/Setting/detail',
					method: 'POST',
					headers: {
						'Content-Type': 'application/x-www-form-urlencoded'
					}
				}).success(function(res) {
                    $scope.loading_show = false;
					$scope.company_info = true;
					$scope.Compinfo = res.data;
					if($scope.app.user.data.role_id!=1){
						if(!$scope.Compinfo.description){
							$scope.Compinfo.description="老板太懒，还未写下任何简介"
						}
					}
					//企业信息
					$scope.comp = function() {
							$('.nav_left').find('a').removeClass('active');
							$('.nav_left').eq('0').find('a').addClass('active');
							$scope.company_info = true;
							$scope.pay_info = false;
							$scope.out_info = false;
						},
						//付费信息
						$scope.money = function() {
							$('.nav_left').find('a').removeClass('active');
							$('.nav_left').eq('1').find('a').addClass('active');
							$scope.company_info = false;
							$scope.out_info = false;
							$scope.pay_info = true;
						},
						//退出
						$scope.out = function() {
							$('.nav_left').find('a').removeClass('active');
							$('.nav_left').eq('2').find('a').addClass('active');
							$scope.pay_info = false;
							$scope.company_info = false;
							$scope.out_info = true;
						}
					if($scope.Compinfo.status == 0) {
						$scope.Compinfo.statue_name = "待生效";
					}
					if($scope.Compinfo.status == 1) {
						$scope.Compinfo.statue_name = "使用中";
					}
                    if($scope.Compinfo.status == 2) {
						$scope.Compinfo.statue_name = "已过期";
					}                    
					if($scope.Compinfo.status == 3) {
						$scope.Compinfo.statue_name = "已终止";
					}
					

				});

			},
			init: function() {
				$scope.Compinfo = [];
				this._getCompinfo && this._getCompinfo();
			}
		};
		$scope.load.init && $scope.load.init();
		
		//编辑保存
		$scope.save=function(){
			var compinfo=$.trim($('.comp_list textarea[name="company_introduce"]').val());	
			$http({
					url: app._baseUrl + '/QyManage/Setting/edit',
					method: 'POST',
					data:{
						description:compinfo
					},
					headers: {
						'Content-Type': 'application/x-www-form-urlencoded'
					}
				}).success(function(res) {
					location.reload([true])   
				})
		}
        
        $scope.outcomp=function(){
			$scope.tipModal.show();	
		}
        
        
        $scope.tipModal = {
			isShow: false,
			title: '退出企业',
			data: {},
			confirm: function() {
				$http({
					url: app._baseUrl + '/QyManage/Setting/secede',
					method: 'POST',
					headers: {
						'Content-Type': 'application/x-www-form-urlencoded'
					}
			}).success(function(res) {
				})
				this.hide();
				var url = $state.href('app.myCourse');
				window.location.href = url;
			},
			cancel: function() {
				this.hide()
			},
			hide: function() {
				this.isShow = false;
			},
			show: function() {
				this.isShow = true;
			}
		}
	})
})